﻿using System;
using System.IO;
using Galaxy.ModuleInterface;
using Galaxy.ModuleInterface.Messages;

namespace Galaxy.TestModule
{
    public class TextWriterModule : GalaxyModule
    {
        private string f_Text;
        private readonly TextWriter f_TextWriter;


        public TextWriterModule(TextWriter Writer, string Text)
            : base("Принтер")
        {
            f_Text = Text;
            f_TextWriter = Writer;
        }

        public TextWriterModule(string Name, TextWriter Writer, string Text)
            : base(Name)
        {
            f_Text = Text;
            f_TextWriter = Writer;
        }

        public override void Start()
        {
#if DEBUG
            Console.WriteLine("Принтер запущен");
#endif
        }

        public override void Stop()
        {
#if DEBUG
            Console.WriteLine("Принтер остановлен");
#endif
        }

        public override void Initialize()
        {
#if DEBUG
            Console.WriteLine("Принтер проинициализирован");
#endif
        }

        public override void ProcessMessage(IGalaxyModuleMessage Message)
        {
            base.ProcessMessage(Message);
            ProcessMessage(Message as TextMessage);
            ProcessMessage(Message as InvokeMessage);
        }

        protected virtual void ProcessMessage(InvokeMessage Message)
        {
            if(Message == null)
                return;
            f_TextWriter.WriteLine(f_Text);
            System.Windows.Forms.MessageBox.Show(f_Text);
        }

        protected virtual void ProcessMessage(TextMessage Message)
        {
            if(Message == null)
                return;
            f_Text = Message.Data;
        }
    }
}
